package com.example.community.controller;

import com.example.community.enity.Book;
import com.example.community.service.BookService;
import org.apache.ibatis.annotations.Param;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {

    Logger logger = Logger.getLogger(BookController.class);
    @Autowired
    BookService bookService;

    @GetMapping("/getBookList/{page}/{size}")
    public List<Book> getBookList(@PathVariable("page") int page,@PathVariable("size") int size){
        logger.error("测试日志是否输出");
        return bookService.getBookList(page,size);
    }
    @PostMapping("/add")
    public String addBook(@RequestBody Book book){
        int a = bookService.addBook(book);
        return a==1?"success":"error";
    }

    @GetMapping("/get/{bookID}")
    public Book findBook(@PathVariable("bookID")int bookID){
        return bookService.findById(bookID);
    }
    @PutMapping("/update")
    public String insertBokk(@RequestBody Book book){
        int a = bookService.updateBook(book);
        return a==1?"success":"error";
    }
    @DeleteMapping("/delete/{bookID}")
    public String deleteBook(@PathVariable("bookID")int bookID){
        int a = bookService.deleteBook(bookID);
        return a==1?"success":"error";
    }
}
